home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17562 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  56 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!marnold
  3. From: marnold@netcom.com (Matt Arnold)
  4. Subject: Re: Pure virtual destructors?
  5. Message-ID: <marnoldDpxyGI.2G5@netcom.com>
  6. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  7. References: <4kuq0i$p6t@ftp.ee.vill.edu> <marnoldDpxt3n.F12@netcom.com>
  8. Date: Tue, 16 Apr 1996 06:09:54 GMT
  9. Sender: marnold@netcom19.netcom.com
  10.  
  11. marnold@netcom.com (Matt Arnold) writes:
  12.  
  13. >sheridan@monet.vill.edu writes:
  14.  
  15.  
  16. >>The rule with destructors is that they are always overridden, right?
  17. >>That's a quote from VC4 docs, BTW.  When I do this:
  18.  
  19. >>class CBase {
  20. >>public:
  21. >>    virtual ~CBase() = 0;
  22. >>...};
  23.  
  24. >>class CChild : public CBase {
  25. >>public:
  26. >>    ~CChild();
  27. >>...};
  28.  
  29. >>and declare a body for ~CChild, I always get unresolved external on
  30. >>CBase::~CBase.  I have seen this in several cases.  My guess is it's not
  31. >>a compiler bug, so what am I missing?
  32.  
  33. >You're missing the fact that virtual destructors are *always* called, 
  34. >even pure ones (in your example, before ~CChild is executed, ~CBase
  35.                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  36. >*will* be executed no matter what).  You get link errors because the
  37.  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  38.  
  39. Whoa!  I said that backwards!!!  The "Reverse" key on my terminal must
  40. evah neeb kcuts nwod (NMAD! There it goes again.)
  41.  
  42. The above should have been "~CBase will always be executed after ~Child 
  43. executes, no matter what".  This is because, of course, objects are
  44. destroyed in exactly the opposite sequence that they were constructed 
  45. in.  Sorry for any confusion.
  46.  
  47. >compiler is looking for the CBase::~CBase() you forgot to define.
  48.  
  49. -------------------------------------------------------------------------
  50. Matt Arnold                       |        | ||| | |||| |  | | || ||
  51. marnold@netcom.com                |        | ||| | |||| |  | | || ||
  52. Boston, MA                        |      0 | ||| | |||| |  | | || ||
  53. 617.389.7384 (h) 617.576.2760 (w) |        | ||| | |||| |  | | || ||
  54. C++, MIDI, Win32/95 developer     |        | ||| 4 3 1   0 8 3 || ||
  55. -------------------------------------------------------------------------
  56.